package controller;

import com.jfinal.core.Controller;

/**
 * Created by Administrator on 2018/3/23 0023.
 */
public class MainController extends Controller {


    public void index() {
        renderHtml("OK!");
    }
    public void hello() {
        String username = getPara("username");
        setAttr("username", username);
        renderFreeMarker("hello.ftl");
    }

    public void register() {
        renderFreeMarker("register.ftl");
    }

    public void doRegister() {
        String username = getPara("username");
        int gender = getParaToInt("gender");
        String password = getPara("password");
        String hometown = getPara("hometown");

        setAttr("username", username);
        setAttr("hometown", hometown);
        setAttr("gender", gender);
        if(gender == 0){
            setAttr("title", "女士");
        }
        else{
            setAttr("title", "先生");
        }
        renderFreeMarker("register-result.ftl");
    }
    public void login(){
        renderFreeMarker("login.ftl");
    }
    public void doLogin(){
        String username = getPara("username");
        String password = getPara("password");
        //renderText(username.equals("123") + "  " + password.equals("123"));
        if(username.equals("mazhijun") && password.equals("123")){
            renderHtml("<h1>登录成功</h1>");
        }else{
            renderHtml("<h1>登录失败</h1><br><a href = \"/login\">返回登录</a>");
        }
    }
}
